<?php
namespace framework\dispatcher;

/**
 * 控制台脚本请求分发器
 */
class ShellDispatcher extends DispatcherBase
{
    /**
     * 初始化请求分发器
     *
     * @return void
     */
    public function initialize()
    {
        $action = (array_key_exists("argv", $_SERVER) && count($_SERVER['argv']) > 1) ? $_SERVER['argv'][1] : 'Job.exec';

        if (preg_match('/^([a-z_]+)\.([a-z_]+)$/i', $action, $items))
        {
            $this->ctrlName   = $items[1] . 'Ctrl';
            $this->methodName = $items[2];
        }
    }

    /**
     * 获取请求分发参数
     *
     * @return array
     */
    public function getParams()
    {
        return empty($_SERVER['argv']) ? array() : $_SERVER['argv'];
    }
}